/**
 * 
 */
package com.wilmar.process.entity.vo;

import java.text.SimpleDateFormat;

import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.task.Task;

import com.wilmar.process.core.ProcessSystemDeclareKeys;

/**
 * @author MaKuBEX E-mail:makubexnet@gmail.com
 * @version 1.0.0 at Aug 4, 2009 10:28:06 AM
 * 
 */
public class TaskInstanceVO extends AbstractValueObject implements ValueObject {

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = -3690922063882485116L;

	private String activityName;
	private String createTime;
	private String description;
	private String name;
	private String form;
	private String assignee;
	private String id;
	private String executionId;
	private String processInstanceId;
	private String processInstanceKey;
	private String processDefinitionId;
	private String processDefinitionName;

	private boolean taken;

	/**
	 * 完整构造函数，直接由一个task对象转换而来
	 * 
	 * @param task
	 *            任务实例
	 * @param pi
	 *            流程实例
	 * @param pd
	 *            流程定义
	 */
	public TaskInstanceVO(Task task, ProcessInstance pi, ProcessDefinition pd) {
		this.id = task.getId();
		this.activityName = task.getActivityName();
		SimpleDateFormat sdf = new SimpleDateFormat(
				ProcessSystemDeclareKeys.SYSTEM_LONG_DATE_FORMAT
						+ ProcessSystemDeclareKeys.SPACE
						+ ProcessSystemDeclareKeys.SYSTEM_LONG_TIME_FORMAT);
		this.createTime = sdf.format(task.getCreateTime());
		this.description = task.getDescription();
		this.name = task.getName();
		this.form = task.getFormResourceName();
		if (task.getAssignee() == null
				|| task.getAssignee().trim().length() == 0) {
			this.assignee = "";
			this.taken = false;
		} else {
			this.assignee = task.getAssignee();
			this.taken = true;
		}
		this.executionId = task.getExecutionId();
		if (pi != null) {
			this.processInstanceId = pi.getId();
			this.processInstanceKey = pi.getKey();
		}
		if (pd != null) {
			this.processDefinitionName = pd.getName();
			this.processDefinitionId = pd.getId();
		}
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TaskInstanceVO other = (TaskInstanceVO) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	/**
	 * @return the activityName
	 */
	public String getActivityName() {
		return activityName;
	}

	/**
	 * @return the assignee
	 */
	public String getAssignee() {
		return assignee;
	}

	/**
	 * @return the createTime
	 */
	public String getCreateTime() {
		return createTime;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @return the form
	 */
	public String getForm() {
		return form;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	/**
	 * @param activityName
	 *            the activityName to set
	 */
	public void setActivityName(String activityName) {
		this.activityName = activityName;
	}

	/**
	 * @param assignee
	 *            the assignee to set
	 */
	public void setAssignee(String assignee) {
		this.assignee = assignee;
	}

	/**
	 * @param createTime
	 *            the createTime to set
	 */
	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @param form
	 *            the form to set
	 */
	public void setForm(String form) {
		this.form = form;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the executionId
	 */
	public String getExecutionId() {
		return executionId;
	}

	/**
	 * @param executionId
	 *            the executionId to set
	 */
	public void setExecutionId(String executionId) {
		this.executionId = executionId;
	}

	/**
	 * @return the processInstanceId
	 */
	public String getProcessInstanceId() {
		return processInstanceId;
	}

	/**
	 * @param processInstanceId
	 *            the processInstanceId to set
	 */
	public void setProcessInstanceId(String processInstanceId) {
		this.processInstanceId = processInstanceId;
	}

	/**
	 * @return the processDefinitionName
	 */
	public String getProcessDefinitionName() {
		return processDefinitionName;
	}

	/**
	 * @param processDefinitionName
	 *            the processDefinitionName to set
	 */
	public void setProcessDefinitionName(String processDefinitionName) {
		this.processDefinitionName = processDefinitionName;
	}

	/**
	 * @return the processInstanceKey
	 */
	public String getProcessInstanceKey() {
		return processInstanceKey;
	}

	/**
	 * @param processInstanceKey
	 *            the processInstanceKey to set
	 */
	public void setProcessInstanceKey(String processInstanceKey) {
		this.processInstanceKey = processInstanceKey;
	}

	/**
	 * @return the processDefinitionId
	 */
	public String getProcessDefinitionId() {
		return processDefinitionId;
	}

	/**
	 * @param processDefinitionId
	 *            the processDefinitionId to set
	 */
	public void setProcessDefinitionId(String processDefinitionId) {
		this.processDefinitionId = processDefinitionId;
	}

	/**
	 * @return the taken
	 */
	public boolean isTaken() {
		return taken;
	}

	/**
	 * @param taken
	 *            the taken to set
	 */
	public void setTaken(boolean taken) {
		this.taken = taken;
	}
}
